package com.dongyoufa.senior1.month.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.dongyoufa.senior1.month.entity.Order;
import com.dongyoufa.senior1.month.service.OrderService;
import com.github.pagehelper.PageInfo;

@Controller
public class OrderController {
	@Autowired
	private OrderService orderService;
	@RequestMapping("list")
	public String getlist(@RequestParam(defaultValue = "1")Integer pageNum,@RequestParam(defaultValue = "2")Integer pageSize,Order order,Model model) {
		PageInfo<Order> info = orderService.getlist(pageNum,pageSize,order);
		model.addAttribute("info", info);
		model.addAttribute("order", order);
		return "list";
	}
	@RequestMapping("insert")
	public String insert(Model model) {
		model.addAttribute("orders", new Order());
		return "inserts";
	}
	@RequestMapping("toinsert")
	public String toinsert(@Validated @ModelAttribute Order orders) {
		System.out.println(orders);
		Integer insertorder = orderService.insertorder(orders);
		System.out.println("============================================"+insertorder);
		return "redirect:list";
	}
}
